//
//  JSTInterestcircleFootView.m
//  KYKJPackDemo
//
//  Created by 01 on 17/5/11.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTInterestcircleFootView.h"
#import "JSTInterestcircleFootFrame.h"
#import "JSTInterestcircleDataModel.h"

@implementation JSTInterestcircleFootView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        // 分割线
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, .25)];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:lineView];
        
        UILabel *timeLabel = [[UILabel alloc] init];
        timeLabel.font = kSystemFont(kCurrentScreenWidth(9));
        timeLabel.textColor = [UIColor colorWithHexString:@"9fa0a0"];
        [self addSubview:timeLabel];
        self.timeLabel = timeLabel;
        
        UIButton *replyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [replyBtn setTitle:@"" forState:UIControlStateNormal];
        [replyBtn setImage:[UIImage imageNamed:@"Interest_comment_normal"] forState:UIControlStateNormal];
        [replyBtn setImage:[UIImage imageNamed:@"Interest_comment_hover"] forState:UIControlStateSelected];
        [replyBtn addTarget:self action:@selector(changeReplyController:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:replyBtn];
        self.replyBtn = replyBtn;
        
        UIButton *fabulousBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
        [fabulousBtn setTitle:@"" forState:UIControlStateNormal];
        [fabulousBtn setImage:[UIImage imageNamed:@"Interest_thumbs_normal"] forState:UIControlStateNormal];
        [fabulousBtn setImage:[UIImage imageNamed:@"Interest_thumbs_hover"] forState:UIControlStateSelected];
        [fabulousBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [fabulousBtn setTitleColor:kRedColor forState:UIControlStateSelected];
        [fabulousBtn addTarget:self action:@selector(changeFabulous:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:fabulousBtn];
        self.fabulousBtn = fabulousBtn;
    }
    return self;
}

- (void)setFootFrame:(JSTInterestcircleFootFrame *)footFrame
{
    _footFrame = footFrame;
    self.frame = _footFrame.frame;
    
    _model = footFrame.model;
    
    self.timeLabel.text = _model.timeText;
    self.timeLabel.frame = footFrame.timeFrame;
    
    self.fabulousBtn.frame = footFrame.fabulousFrame;
    [self.fabulousBtn setTitle:_model.pointPraise forState:UIControlStateNormal];
//    if (_model.praiseStatus)
//    {
//        self.fabulousBtn.selected = YES;
//    }
    
    self.replyBtn.frame = footFrame.replyFrame;
    [self.replyBtn setTitle:_model.commentNumber forState:UIControlStateNormal];
    [self.replyBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
}

- (void) changeFabulous:(UIButton *)btn
{
    if (_delegate && [_delegate respondsToSelector:@selector(praiseOnclick:)]) {
        [_delegate praiseOnclick:_model.dynamicId];
    }
}

- (void) changeReplyController:(UIButton *)btn
{
    if (_delegate && [_delegate respondsToSelector:@selector(changeCommetnPage:)]) {
        [_delegate changeCommetnPage:_footFrame.model.dynamicId];
    }
}
@end
